home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / grobda.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  5KB  |  200 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12. static int flipscreen;
  13. extern unsigned char *grobda_spriteram;
  14.  
  15.  
  16. /***************************************************************************
  17.  
  18.   Convert the color PROMs into a more useable format.
  19.  
  20.   Grodba has one 32x8 palette PROM and two 256x4 color lookup table PROMs
  21.   (one for characters, one for sprites).
  22.   The palette PROM is connected to the RGB output this way:
  23.  
  24.   bit 7 -- 220 ohm resistor  -- BLUE
  25.         -- 470 ohm resistor  -- BLUE
  26.         -- 220 ohm resistor  -- GREEN
  27.         -- 470 ohm resistor  -- GREEN
  28.         -- 1  kohm resistor  -- GREEN
  29.         -- 220 ohm resistor  -- RED
  30.         -- 470 ohm resistor  -- RED
  31.   bit 0 -- 1  kohm resistor  -- RED
  32.  
  33. ***************************************************************************/
  34. void grobda_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  35. {
  36.     int i;
  37.  
  38.     for (i = 0;i < 32;i++)
  39.     {
  40.         int bit0,bit1,bit2;
  41.  
  42.         bit0 = (color_prom[i] >> 0) & 0x01;
  43.         bit1 = (color_prom[i] >> 1) & 0x01;
  44.         bit2 = (color_prom[i] >> 2) & 0x01;
  45.         palette[3*i] = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  46.         bit0 = (color_prom[i] >> 3) & 0x01;
  47.         bit1 = (color_prom[i] >> 4) & 0x01;
  48.         bit2 = (color_prom[i] >> 5) & 0x01;
  49.         palette[3*i + 1] = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  50.         bit0 = 0;
  51.         bit1 = (color_prom[i] >> 6) & 0x01;
  52.         bit2 = (color_prom[i] >> 7) & 0x01;
  53.         palette[3*i + 2] = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  54.     }
  55.     /* characters */
  56.     for (i = 0; i < 256; i++)
  57.         colortable[i] = (0x1f - (color_prom[i + 32] & 0x0f));
  58.     /* sprites */
  59.     for (i = 256; i < 512; i++)
  60.         colortable[i] = (color_prom[i + 32] & 0x0f);
  61. }
  62.  
  63.  
  64.  
  65. int grobda_vh_start( void )
  66. {
  67.     /* set up spriteram area */
  68.     spriteram_size = 0x80;
  69.     spriteram = &grobda_spriteram[0x780];
  70.     spriteram_2 = &grobda_spriteram[0x780+0x800];
  71.     spriteram_3 = &grobda_spriteram[0x780+0x800+0x800];
  72.  
  73.     return generic_vh_start();
  74. }
  75.  
  76. void grobda_vh_stop( void )
  77. {
  78.     generic_vh_stop();
  79. }
  80.  
  81. WRITE_HANDLER( grobda_flipscreen_w )
  82. {
  83.     if (flipscreen != data)
  84.         memset(dirtybuffer,1,videoram_size);
  85.     flipscreen = data;
  86. }
  87.  
  88.  
  89. /***************************************************************************
  90.  
  91.     Screen Refresh
  92.  
  93. ***************************************************************************/
  94.  
  95. static void grobda_draw_sprites(struct osd_bitmap *bitmap)
  96. {
  97.     int offs;
  98.  
  99.     for (offs = 0; offs < spriteram_size; offs += 2){
  100.         int number = spriteram[offs];
  101.         int color = spriteram[offs+1];
  102.         int sx = (spriteram_2[offs+1]-40) + 0x100*(spriteram_3[offs+1] & 1);
  103.         int sy = 28*8-spriteram_2[offs] - 16;
  104.         int flipx = spriteram_3[offs] & 1;
  105.         int flipy = spriteram_3[offs] & 2;
  106.         int width,height;
  107.  
  108.         if (flipscreen){
  109.             flipx = !flipx;
  110.             flipy = !flipy;
  111.         }
  112.  
  113.         if (spriteram_3[offs+1] & 2) continue;
  114.  
  115.         switch (spriteram_3[offs] & 0x0c){
  116.             case 0x0c:    /* 2x both ways */
  117.                 width = height = 2; number &= (~3); break;
  118.             case 0x08:    /* 2x vertical */
  119.                 width = 1; height = 2; number &= (~2); break;
  120.             case 0x04:    /* 2x horizontal */
  121.                 width = 2; height = 1; number &= (~1); sy += 16; break;
  122.             default:    /* normal sprite */
  123.                 width = height = 1; sy += 16; break;
  124.         }
  125.  
  126.         {
  127.             static int x_offset[2] = { 0x00, 0x01 };
  128.             static int y_offset[2] = { 0x00, 0x02 };
  129.             int x,y, ex, ey;
  130.  
  131.             for( y=0; y < height; y++ ){
  132.                 for( x=0; x < width; x++ ){
  133.                     ex = flipx ? (width-1-x) : x;
  134.                     ey = flipy ? (height-1-y) : y;
  135.  
  136.                     drawgfx(bitmap,Machine->gfx[1],
  137.                         (number)+x_offset[ex]+y_offset[ey],
  138.                         color,
  139.                         flipx, flipy,
  140.                         sx+x*16,sy+y*16,
  141.                         &Machine->drv->visible_area,
  142.                         TRANSPARENCY_PEN,0);
  143.                 }
  144.             }
  145.         }
  146.     }
  147. }
  148.  
  149. void grobda_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  150. {
  151.     int offs;
  152.  
  153.     for (offs = videoram_size - 1; offs > 0; offs--)
  154.     {
  155.         if (dirtybuffer[offs])
  156.         {
  157.             int mx,my,sx,sy;
  158.  
  159.             dirtybuffer[offs] = 0;
  160.             mx = offs % 32;
  161.             my = offs / 32;
  162.  
  163.             if (my < 2)
  164.             {
  165.                 if (mx < 2 || mx >= 30) continue; /* not visible */
  166.                 sx = my + 34;
  167.                 sy = mx - 2;
  168.             }
  169.             else if (my >= 30)
  170.             {
  171.                 if (mx < 2 || mx >= 30) continue; /* not visible */
  172.                 sx = my - 30;
  173.                 sy = mx - 2;
  174.             }
  175.             else
  176.             {
  177.                 sx = mx + 2;
  178.                 sy = my - 2;
  179.             }
  180.  
  181.             if (flipscreen)
  182.             {
  183.                 sx = 35 - sx;
  184.                 sy = 27 - sy;
  185.             }
  186.  
  187.             drawgfx(tmpbitmap,Machine->gfx[0],
  188.                     videoram[offs],
  189.                     colorram[offs] & 0x3f,
  190.                     flipscreen,flipscreen,
  191.                     sx*8,sy*8,
  192.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  193.         }
  194.     }
  195.  
  196.     copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  197.  
  198.     grobda_draw_sprites(bitmap);
  199. }
  200.